package com.lagou.demo.controller;

import com.lagou.demo.service.IDemoService;
import com.lagou.demo.service.IUserService;
import com.lagou.edu.mvcframework.annotations.*;
import com.lagou.edu.mvcframework.pojo.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@LagouController
@LagouRequestMapping("/demo")
@LagouSecurity(value = {"Tom", "Jack"})
public class DemoController {


    @LagouAutowired
    private IDemoService demoService;

    @LagouAutowired
    private IUserService userService;


    /**
     * URL: /demo/query?name=lisi
     *
     * @param request
     * @param response
     * @param name
     * @return
     */
    @LagouRequestMapping("/query")
    public String query(HttpServletRequest request, HttpServletResponse response, String name) {
        return demoService.get(name);
    }


    @LagouSecurity(value = "Tom")
    @LagouRequestMapping("/info")
    public String info(HttpServletRequest request, HttpServletResponse response, String username) {
        User user = userService.findByUsername(username);
        return user != null ? user.toString() : "null";
    }

}
